package com.protocols.sctp.m3ua.sccp.tcap;

import com.protocols.GeneralProtocolData;
import com.protocols.OctaveInteger;
import com.protocols.ProtoOperations;
import com.protocols.ProtocolStackException;
import com.protocols.sctp.m3ua.sccp.SccpUnitDataMsg;

public class TcapEnd implements GeneralProtocolData{

	private TcapConstructor End = new TcapConstructor(0x64);
	private TcapPrimitiveUnitNumber DestinationTransactionID = new TcapPrimitiveUnitNumber(0x49);
	private TcapConstructor DialogPortion = new TcapConstructor(0x6b);
	private TcapConstructor External = new TcapConstructor(0x28);
	private TcapPrimitiveUnitByteArray ObjectID = new TcapPrimitiveUnitByteArray(0x06);
	private TcapConstructor DialogAsID = new TcapConstructor(0xA0);
	private TcapConstructor DialogResponsePDU = new TcapConstructor(0x61);
	private TcapPrimitiveUnitNumber ProtocolVersion = new TcapPrimitiveUnitNumber(0x80);
	private TcapConstructor ApplicationContextContainer = new TcapConstructor(0xA1);
	private TcapPrimitiveUnitNumber ApplicationContext = new TcapPrimitiveUnitNumber(0x06);		
	private TcapConstructor ResultContainer = new TcapConstructor(0xA2);
	private TcapPrimitiveUnitNumber Result = new TcapPrimitiveUnitNumber(0x02);
	private TcapConstructor ResultSourceDiagonostic = new TcapConstructor(0xA3);
	private TcapConstructor DialogServiceUserContainer = new TcapConstructor(0xA1);	
	private TcapPrimitiveUnitNumber DialogServiceUser = new TcapPrimitiveUnitNumber(0x02);	
	private TcapConstructor DialogServiceProviderContainer = new TcapConstructor(0xA2);	
	private TcapPrimitiveUnitNumber DialogServiceProvider = new TcapPrimitiveUnitNumber(0x02);	
	private TcapConstructor UserInformationContainer = new TcapConstructor(0xbe);	
	private TcapPrimitiveUnitByteArray UserInformation = new TcapPrimitiveUnitByteArray(0x28);		
	public TcapConstructor ComponentPortion = new TcapConstructor(0b01101100);
	public TcapEnd() {

		End.addElement(DestinationTransactionID);	
		End.addElement(DialogPortion);
		DialogPortion.addElement(External);
		External.addElement(ObjectID);
		External.addElement(DialogAsID);
		DialogAsID.addElement(DialogResponsePDU);
		DialogResponsePDU.addElement(ProtocolVersion);
		DialogResponsePDU.addElement(ApplicationContextContainer);
		ApplicationContextContainer.addElement(ApplicationContext);		
		DialogResponsePDU.addElement(ResultContainer);
		ResultContainer.addElement(Result);
		DialogResponsePDU.addElement(ResultSourceDiagonostic);		
		ResultSourceDiagonostic.addElement(DialogServiceUserContainer);
		DialogServiceUserContainer.addElement(DialogServiceUser);		
		ResultSourceDiagonostic.addElement(DialogServiceProviderContainer);
		DialogServiceProviderContainer.addElement(DialogServiceProvider);
		DialogResponsePDU.addElement(UserInformationContainer);
		UserInformationContainer.addElement(UserInformation);
		End.addElement(ComponentPortion);
		
		
		
	}

	public void setApplicationContext(long appcontext){
		ApplicationContext.setTagValue(appcontext);
	}
	
	public long getApplicationContext(){
		return ApplicationContext.getTagValue();
	}
	
	public void setObjectID(byte[] objectid){
		ObjectID.setTagValue(objectid);
	}
	
	public byte[] getObjectID(){
		return ObjectID.getTagValue();
	}
	
	public byte [] getByteArray(){	
		return End.getByteArray();
		

	}
	
	
	public int getLength(){
		return getByteArray().length;
	}
	

	public long getDestinationTransactionID() {
		return DestinationTransactionID.getTagValue();
	}

	public void setDestinationTransactionID(long destinationTransactionID) {
		DestinationTransactionID.setTagValue( destinationTransactionID);
	}

	@Override
	public byte[] decode(byte[] input) throws ProtocolStackException {
		input=ProtoOperations.extractByteArray(input, 1, input.length-1);
		
		return End.decode(input);
	}

	
	
	
}
